package com.example.administrator.recyclevviewtest419szy.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.administrator.recyclevviewtest419szy.R;
import com.example.administrator.recyclevviewtest419szy.adapter.MyAdapter;
import com.example.administrator.recyclevviewtest419szy.adapter.TcaseMyAdapter;
import com.example.administrator.recyclevviewtest419szy.bean.ArticleBean;
import com.example.administrator.recyclevviewtest419szy.bean.TcaseArticleBean;
import com.example.administrator.recyclevviewtest419szy.iface.ArticleListener;
import com.example.administrator.recyclevviewtest419szy.iface.TcaseArticleListener;
import com.example.administrator.recyclevviewtest419szy.model.ArticleModel;
import com.example.administrator.recyclevviewtest419szy.model.TcaseArticleModel;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private TcaseMyAdapter tcasemyAdapter;
    private List<TcaseArticleBean> list=null;
    TcaseArticleListener tcasearticleListener=new TcaseArticleListener() {
        @Override
        public void onResponse(List<TcaseArticleBean> beenlist) {
            list=beenlist;
            tcasemyAdapter.setList(list);
            tcasemyAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initReyclerView();

        TcaseArticleModel tcasearticleModel=new TcaseArticleModel();
        tcasearticleModel.getResultList("tcase",2,"rv1l2tidbomann2qn86nln6ur2",tcasearticleListener);
    }

    private void initReyclerView() {
        //获取,RecyclerView
        recyclerView=(RecyclerView)findViewById(R.id.recyclerview);
        //布局
        layoutManager=new LinearLayoutManager(this);
        //布局管理器
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        //
        // list=getData();
        tcasemyAdapter=new TcaseMyAdapter(this);
        tcasemyAdapter.setList(list);
        recyclerView.setAdapter(tcasemyAdapter);

    }

}
